***This do-file runs the regressions found in table O1 of the appendix
**Curtis RESTAT
**Change to directory where data and code were downloaded
**cd 

set matsize 1500
clear all
set more off

use cbp_st_tableO1,clear

drop if enint==0 /*keeps only MFTG Industries*/
drop if fipstate=="11" /*Drops DC*/
drop if year==2009

do dataclean_tableO1.do

gen empweight2=emp if year==1998
bysort stateind:carryforward empweight2,replace

so stateind year
egen empweight3t=mean(emp),by(stateind post)
replace empweight3t=. if post==1
egen empweight3=max(empweight3t),by(stateind)

gen eaststr="east" if east==1
replace eaststr="west" if eaststr==""
gen eastind=eaststr+naics

drop yeardum*
qui tab year,gen(yeardum)

gen trend=year-1997
qui tab fipstate,gen(STdum)
foreach var of varlist ind1-ind21 {
qui gen trend`var'=`var'*trend
}

foreach x of varlist STdum1-STdum49 {
qui gen trend`x'=`x'*trend
}

/* Generate Seperate East/West Trends by Industry*/
forvalues i = 1(1)21 {
  qui gen eindtrend`i' = trendind`i'*east
 }
forvalues i = 1(1)21 {
  qui gen windtrend`i' = trendind`i'*((east-1)^2)
 }
tostring east,replace
gen yearindreg=yearind+"_"+east


qui tab yearind,gen(yearinddum)
qui tab STyear, gen(STyeardum)
qui tab stateind, gen(stateinddum)

/* Defines RHS variables to be included in every regression*/
mac def rhs_vars "postxint intxeast postxeast  "




/*Full FE models without 2009*/
*Column 1
qui eststo:areg lemp postxeastxint postxint intxeast postxeast yeardum* [aweight=empweight2],abs(stateind) rob cluster(eastind)
*Column 2
qui eststo:areg lemp postxeastxint postxint intxeast postxeast yearinddum* trendSTdum* [aweight=empweight2],abs(stateind) rob cluster(eastind)
*Column 3
qui eststo:areg lemp postxeastxint postxint intxeast yearinddum* STyeardum* [aweight=empweight2],abs(stateind) rob cluster(eastind)
*Column 4
qui eststo:areg lemp postxeastxint postxint intxeast postxeast yeardum* windtrend* eindtrend*[aweight=empweight2],abs(stateind) rob cluster(eastind)
*Column 5
qui eststo:areg lemp postxeastxint postxint intxeast postxeast yearinddum* trendSTdum* windtrend* eindtrend*[aweight=empweight2],abs(stateind) rob cluster(eastind)
*Column 6
qui eststo:areg lemp postxeastxint postxint intxeast  yearinddum* STyeardum* windtrend* eindtrend*[aweight=empweight2],abs(stateind) rob cluster(eastind)

outreg2 [est1 est2 est3 est4 est5 est6] using "tableO1.tex",keep(postxeastxint postxeast) nocons replace

eststo clear
